//
//  BankInfoCollectionCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/8.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class BankInfoCollectionCell: BaseTableViewCell {
    @IBOutlet weak var leftLabel: UILabel!
    
    
    @IBOutlet weak var rightTextField: UITextField!
    
    var model : BankInfoModel?
    
    var index : IndexPath?{
        
        didSet{
        
            if index == nil {
                return
            }
            
            if index?.row == 0 {
                leftLabel.text = "持卡人:"
                
                rightTextField.placeholder = "真实姓名"
                
                rightTextField.text = model?.true_name
                
                rightTextField.isUserInteractionEnabled = true
                
                rightTextField.keyboardType = .default
                
            }else if index?.row == 1 {
                leftLabel.text = "卡号:"
                rightTextField.placeholder = "银行卡号"
                rightTextField.isUserInteractionEnabled = true
                rightTextField.text = model?.bank_number
                rightTextField.keyboardType = .numberPad

                
            }else if index?.row == 2 {
                leftLabel.text = "卡类型:"
                rightTextField.placeholder = "选择银行卡类型"
                rightTextField.isUserInteractionEnabled = false
                
                rightTextField.text = model?.bank_name
                
            }else if index?.row == 3 {
                leftLabel.text = "手机号:"
                rightTextField.placeholder = "使用中的手机号"
                rightTextField.isUserInteractionEnabled = true
                rightTextField.text = model?.mob_phone
                rightTextField.keyboardType = .numberPad

                
            }
            

        
        }
    
        
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        
        NotificationCenter.default.addObserver(self, selector: #selector(textChange), name: NSNotification.Name.UITextFieldTextDidChange, object: rightTextField)
        // Initialization code
    }
    
    
    func textChange(){
        
        if index?.row == 0 {
            
            model?.true_name = rightTextField.text
            
        }else if index?.row == 1 {
            
            model?.bank_number = rightTextField.text
            
        }else if index?.row == 2 {
            
            model?.bank_name = rightTextField.text
            
        }else if index?.row == 3 {
            
            model?.mob_phone = rightTextField.text
        }
        
        

        
    }
    
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
